#include <iostream>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>

/* 
 * 程序运行 3 秒后，主线程退出，同时其他次线程也被强制结束了
 */

using namespace std;

#define NUM 5

void * threadRun(void * name)
{
	while (true) {
		cout << "I am other" << (char*)name << endl;
		sleep(1);
	}
	delete[] (char *)name;

	return NULL;
}

int main()
{
	pthread_t pt[NUM];

	for (int i = 0; i < NUM; i++) {
		char *name = new char[64];
		snprintf(name, 64, "thread-%d", i+1);
		pthread_create(pt+i, NULL, threadRun, name);
	}

	sleep(3);

	return 0;
}
